#!/usr/bin/env bash

## Process command line flags ##

source ${SCRIPTS_DIR}/lib/shflags
DEFINE_string 'restart' 'all' "Which lighthouse pods to restart: none, all, agent, coredns"
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"

restart="${FLAGS_restart}"

echo "Running with: restart=${restart}"

set -em

source ${SCRIPTS_DIR}/lib/debug_functions
source ${SCRIPTS_DIR}/lib/deploy_funcs
source ${SCRIPTS_DIR}/lib/utils

import_image quay.io/submariner/lighthouse-agent
import_image quay.io/submariner/lighthouse-coredns

load_settings
declare_kubeconfig

case "${restart}" in
	agent|coredns)
		run_subm_clusters reload_pods deployment submariner-lighthouse-${restart}
		;;
	all)
		run_subm_clusters reload_pods deployment submariner-lighthouse-agent
		run_subm_clusters reload_pods deployment submariner-lighthouse-coredns
		;;
	none)
		;;
	*)
		echo "restart must be one of: none, agent, coredns or all (default)"
		exit 1
		;;
esac
